package cn.anlab.anappframe.util;

import cn.anlab.anappframe.anim.Trans;
import android.app.Activity;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.WindowManager;

public class ViewUtil {

	/**
	 * 获取屏幕的长宽属性
	 * @param context
	 * @return
	 */
    public static DisplayMetrics getDisplayMetrics(Context context) {
        DisplayMetrics dm = new DisplayMetrics();
        WindowManager wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
        wm.getDefaultDisplay().getMetrics(dm);
        return dm;
    }	
    
    /**
     * 设置Activity转换的动画效果
     * @param activity
     * @param tran
     */
    public static void setTransition(Activity activity, Trans tran) {
    	int[] anims = tran.getEnterAndExitAnim();
    	activity.overridePendingTransition(anims[0], anims[1]);
    }
    
    /**
     * 获取颜色
     * @param context
     * @param resId
     * @return
     */
    public static int getColor(Context context, int resId) {
    	return context.getResources().getColor(resId);
    }
    
	/**
	 * 将px转为dip
	 * 
	 * @param context
	 * @param pxValue
	 * @return
	 * @author : wang.jun<br>
	 * @time : 2011-12-14 下午03:47:10<br>
	 */
	public static final int px2dip(Context context, float pxValue) {
		final float scale = context.getResources().getDisplayMetrics().density;
		return (int) (pxValue / scale + 0.5f);
	}

	/**
	 * 将dip转为px
	 * 
	 * @param context
	 * @param dipValue
	 * @return
	 * @author : wang.jun<br>
	 * @time : 2011-12-14 下午03:57:26<br>
	 */
	public static final int dip2px(Context context, float dipValue) {
		final float scale = context.getResources().getDisplayMetrics().density;
		return (int) (dipValue * scale + 0.5f);
	}
    
    
	
}
